package com.ttt.radioapp_core.helpers;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class CheckConnectivity {
	public static boolean isConnectivityOnLine(Context context) {
		boolean isOnline;
		boolean mobileConnected = checkIsConnectedOrConnecting(context,
				ConnectivityManager.TYPE_MOBILE);
		boolean wifiConnected = checkIsConnectedOrConnecting(context,
				ConnectivityManager.TYPE_WIFI);

		if (mobileConnected || wifiConnected)
			isOnline = true;
		else
			isOnline = false;

		return isOnline;
	}

	private static boolean checkIsConnectedOrConnecting(Context context,
			int value) {
		ConnectivityManager cm = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfoMobile = cm.getNetworkInfo(value);
		boolean mobileConnected = false;
		if (netInfoMobile != null)
			mobileConnected = netInfoMobile.isConnectedOrConnecting();
		return mobileConnected;
	}

}